//
//  zhuceViewController.m
//  DaHaiDouBan
//
//  Created by dllo on 15/10/31.
//  Copyright © 2015年 Wang Dahai. All rights reserved.
//

#import "zhuceViewController.h"

@interface zhuceViewController ()

@property (nonatomic, retain) UILabel *aLable;
@property (nonatomic, retain) UILabel *bLable;
@property (nonatomic, retain) UILabel *cLable;
@property (nonatomic, retain) UILabel *dLable;
@property (nonatomic, retain) UILabel *eLable;

@property (nonatomic, retain) UITextField *aTextField;
@property (nonatomic, retain) UITextField *bTextField;
@property (nonatomic, retain) UITextField *cTextField;
@property (nonatomic, retain) UITextField *dTextField;
@property (nonatomic, retain) UITextField *eTextField;

@end

@implementation zhuceViewController
- (void)dealloc
{
    [_aLable release];
    [_bLable release];
    [_cLable release];
    [_dLable release];
    [_eLable release];
    
    [_aTextField release];
    [_bTextField release];
    [_cTextField release];
    [_dTextField release];
    [_eTextField release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];

    UIView *containerView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    containerView.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:containerView];
    [containerView release];
    
    self.aLable = [[UILabel alloc] initWithFrame:CGRectMake(40, 70, 80, 40)];
    self.aLable.text = @"用户名:";
    [containerView addSubview:self.aLable];
    [_aLable release];
    self.aTextField = [[UITextField alloc] initWithFrame:CGRectMake(150, 70, 200, 40)];
    self.aTextField.borderStyle = UITextBorderStyleRoundedRect;
    self.aTextField.keyboardType = UIKeyboardTypeDefault;
    self.aTextField.placeholder = @"请输入用户名";
    [containerView addSubview:self.aTextField];
    [_aTextField release];
    
    self.bLable = [[UILabel alloc] initWithFrame:CGRectMake(40, 120, 80, 40)];
    self.bLable.text = @"密码:";
    [containerView addSubview:self.bLable];
    [_bLable release];
    self.bTextField = [[UITextField alloc] initWithFrame:CGRectMake(150, 120, 200, 40)];
    self.bTextField.borderStyle = UITextBorderStyleRoundedRect;
    self.bTextField.keyboardType = UIKeyboardTypeNumberPad;
    self.bTextField.placeholder = @"请输入密码";
    [containerView addSubview:self.bTextField];
    [_bTextField release];
    
    self.cLable = [[UILabel alloc] initWithFrame:CGRectMake(40, 180, 80, 40)];
    self.cLable.text = @"确认密码:";
    [containerView addSubview:self.cLable];
    [_cLable release];
    self.cTextField = [[UITextField alloc] initWithFrame:CGRectMake(150, 180, 200, 40)];
    self.cTextField.borderStyle = UITextBorderStyleRoundedRect;
    self.cTextField.keyboardType = UIKeyboardTypeNumberPad;
    self.cTextField.placeholder = @"再次输入密码";
    
    [containerView addSubview:self.cTextField];
    [_cTextField release];
    
    self.dLable = [[UILabel alloc] initWithFrame:CGRectMake(40, 240, 80, 40)];
    self.dLable.text = @"手机号:";
    [containerView addSubview:self.dLable];
    [_dLable release];
    self.dTextField = [[UITextField alloc] initWithFrame:CGRectMake(150, 240, 200, 40)];
    self.dTextField.borderStyle = UITextBorderStyleRoundedRect;
    self.dTextField.keyboardType = UIKeyboardTypeNumberPad;
    self.dTextField.placeholder = @"请输入联系方式";
    [containerView addSubview:self.dTextField];
    [_dTextField release];
    
    self.eLable = [[UILabel alloc] initWithFrame:CGRectMake(40, 300, 80, 40)];
    self.eLable.text = @"邮箱:";
    [containerView addSubview:_eLable];
    [_eLable release];
    self.eTextField = [[UITextField alloc] initWithFrame:CGRectMake(150, 300, 200, 40)];
    self.eTextField.borderStyle = UITextBorderStyleRoundedRect;
    self.eTextField.keyboardType = UIKeyboardTypeNumberPad;
    self.eTextField.placeholder = @"请输入邮箱";
    [containerView addSubview:self.eTextField];
    [_eTextField release];
    
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.frame = CGRectMake(100, 400, 40, 40);
    [button1 setTitle:@"注册" forState:UIControlStateNormal];//State陈述，叙述
    [button1 setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(aButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [containerView addSubview:button1];
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    button2.frame = CGRectMake(230, 400, 40, 40);
    [button2 setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [button2 setTitle:@"取消" forState:UIControlStateNormal];
    [containerView addSubview:button2];
    [button2 addTarget:self action:@selector(bButtonAction:) forControlEvents:UIControlEventTouchUpInside];


}

-(void)aButtonAction:(UIButton *)btn
{
    if ([self.aTextField.text isEqualToString:@""]) {
        
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示信息" message:@"姓名不能为空" preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"是的" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            
        }];
        UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"返回" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
            
        }];

        [alertVC addAction:action1];
        [alertVC addAction:action2];
        
        [self presentViewController:alertVC animated:YES completion:^{
            
            
        }];

    }else{
        
      //  存值    [[NSUserDefaults standardUserDefaults] setObject:@"132" forKey:@"5"];
        
      //  取值  NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"5”];

        
        [[NSUserDefaults standardUserDefaults] setObject:self.aTextField.text forKey:@"name"];
        [[NSUserDefaults standardUserDefaults] setObject:self.bTextField.text forKey:@"password"];
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示信息" message:@"注册成功" preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"是的" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            [self.navigationController popViewControllerAnimated:YES];
            
        }];
        
        [alertVC addAction:action1];
        
        [self presentViewController:alertVC animated:YES completion:^{
            
            
        }];

    }
    
}
 
-(void)bButtonAction:(UIButton *)btn
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
